<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../../css/common.css" media="all">

	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-row" id="view">
				<form class="layui-form" lay-filter="test_detail">
					<div class="layui-card">
						<div class="layui-card-body">
							
							<div class="layui-form-item">
								<label class="layui-form-label">状态</label>
								<div class="layui-input-block on_off"></div>
							</div>

							<!--<div class="layui-form-item">
								<div class="layui-form-inline" id="fid">
									<label class="layui-form-label">分类：</label>
								</div>
							</div>-->
							
							<div class="layui-form-item">
								<label class="layui-form-label">客户端</label>
								<div class="layui-input-block icon_type"></div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">名称</label>
								<div class="layui-input-block">
									<input type="text" name="name" placeholder="请输入名称" autocomplete="off" class="layui-input">
								</div>
							</div>
							
							<div class="layui-form-item">
								<div class="layui-form-inline" id="fid">
									<label class="layui-form-label">类型：</label>  
								</div>
								<div class="layui-input-block" id="groupid">
								 	<select lay-search="" lay-filter="groupid" lay-verify="" name="type" class="site_icon_group">
								 		<option title="全部" value=''>全部</option>
								 		<option title="图文管理" value="1">图文管理</option>
								 		<option title="帮助中心" value="2">帮助中心</option>
								 	</select>
								</div>
							</div>
							
							<div class="layui-form-item">
								<label class="layui-form-label">标题</label>
								<div class="layui-input-block">
									<input type="text" name="title" placeholder="请输入副标题" autocomplete="off" class="layui-input">
								</div>
							</div>
							
							<div class="layui-form-item">
								<label class="layui-form-label">排序</label>
								<div class="layui-input-block">
									<input type="text" name="list_id" placeholder="请输入排序" autocomplete="off" class="layui-input">
								</div>
							</div>
							
							<div class="layui-form-item">
								<label class="layui-form-label">备注</label>
								<div class="layui-input-block">
									<textarea type="text" name="notes" placeholder="备注" autocomplete="off" class="layui-textarea"></textarea>
								</div>
							</div>

						</div>
					</div>

					<div class="layui-form-item layui-layout-admin">
						<div class="layui-input-block">
							<div class="layui-footer" style="left: 0;">
								<!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
								<button class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../../js/jquery.min.js"></script>
		<script src="../../../../js/jquery.jqprint-0.3.js"></script>
		<script src="../../../../js/common.js"></script>
		<script>
			var _data = {
				id: getParam('id'),
				type: ''
			}

			layui.config({
				base: '../../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'laytpl', 'laydate'], function() {
				var $ = layui.$,
					admin = layui.admin,
					laytpl = layui.laytpl,
					laydate = layui.laydate,
					form = layui.form;

				var maplist = JSON.parse(localStorage.getItem('lsmap')),
					img_arr1 = [];
				var img_arr2 = [],
					img_arr3 = [];

				on_off_show('radio')
				icon_type_show('checkbox')
				//监听提交
				form.on('submit(demo1)', function(data) {
					var data = data.field;
					_data = Object.assign(_data, data);
					_data.client = ''
					for (item in data){ 
						if(/^c/.test(item)){
							if(item.substr(0,6) == 'client'){
								_data.client += data[item]+','
								console.log(item)
								console.log(data[item])
							} 
						} 
					} 
					
					_data.client = (_data.client.substring(_data.client.length-1) == ',') ? _data.client.substring(0,_data.client.length-1) : _data.client;
					
					layer.confirm('确定提交数据？', function() {
						loading();
						if(_data.id) {
							submitdata(server.site_group_edit);
						} else {
							delete _data.id;
							submitdata(server.site_group_insert);
						}
					}, function() {
						layer.msg('取消操作');
					});
					return false;
				});


				if(_data.id) {
					initdata();
				}

				function submitdata(_url) {
					$.post(_url, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								layer.alert('操作成功', function() {
									parent.layer.closeAll();
									parent.layui.table.reload('test-table-operate');
								});
							} else {
								layer.msg(res.msg);
								layer.closeAll('loading');
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}
				function initdata() {
					$.get(server.site_group_detail, _data, function(res, status) {
						if(status == 'success') {
							if(res.code == 0) {
								var data = res.group
 								$(".on_off input[value=" + data.data.status + "]").attr("checked", true)
								
								if(data.data.type){
									var type_arr = data.data.type.split(',')
									for (var i = 0; i < type_arr.length; i++) {
										$(".icon_type input[value=" + type_arr[i] + "]").attr("checked", true)
									}
								}
								form.val("test_detail", data.data);
								form.render();
							} else {
								layer.msg(res.msg);
							}
						} else {
							layer.msg('服务器连接错误');
						}
					});
				}

			});
		</script>
	</body>

</html>